import { setAccountState } from '@/filters/status';
// 成本来源：渠道订单（0）
export const orderInfoSetting = [
  { key: 'orderId', type: 'orderId', props: { label: '订单编号', minWidth: '184' }},
  { key: 'costName', props: { label: '成本项', minWidth: '150' }},
  { key: 'priceBase', type: 'price', props: { align: 'right', label: '结算基数(元)', minWidth: '150' }},
  { key: 'costPrice', type: 'price', props: { align: 'right', label: '结算金额(元)', minWidth: '140' }},
  { key: 'taxAmount', type: 'price', props: { align: 'right', label: '含税金额(元)', minWidth: '140' }},
  { key: 'orderCost', type: 'price', props: { align: 'right', label: '总成本(元)', minWidth: '140' }},
  { key: 'profit', props: { label: '毛利率', minWidth: '100' }},
  { key: 'market', props: { label: '销售', minWidth: '110' }},
  { key: 'resourceName', props: { label: '账号', minWidth: '130' }},
  { key: 'resourceId', props: { label: '账号ID', minWidth: '120' }},
  // { key: 'organization', props: { label: '所属机构', minWidth: '120' }},
  { key: 'operateModeName', props: { label: '运营模式', minWidth: '120' }},
  { key: 'cooperation', props: { label: '合作运营方', minWidth: '120' }},
  { key: 'orderPlatform', props: { label: '下单平台', minWidth: '110' }},
  { key: 'orderTime', type: 'time', props: { label: '下单日期', minWidth: '120' }},
  { key: 'orderForm', props: { label: '下单形式', minWidth: '90' }},
  { key: 'theme', props: { label: '品牌名称', minWidth: '100' }},
  { key: 'contractCode', type: 'contractCode', props: { label: '关联合同', minWidth: '150' }},
  { key: 'costApprovalStatus', props: { label: '审批状态' }},
  { key: 'status', props: { label: '订单状态' }},
  { key: 'writeOffStatus', type: 'filter', filter: setAccountState, props: { label: '核销状态', minWidth: '110' }},
  { key: 'customerName', props: { label: '客户名称', minWidth: '120' }}
];

// 成本来源：商务订单（2）
const sharingModelType = (type) => {
  const obj = { '0': '固定', '1': '分成', '2': '保底+分成' };
  return obj[String(type)] || '--';
};
const ipAryFilter = (ipAry) => {
  if (ipAry && ipAry.length) {
    const ip = [];
    ipAry.forEach(j => {
      const name = `${j.ipFigure || '--'}/${j.ipSeries || '--'}`;
      ip.push(name);
    });
    return ip.join(',');
  }
  return '';
};
const ipInfoSetting = [
  { key: 'orderNum', type: 'ipId', props: { label: '订单编号', minWidth: '184' }},
  { key: 'costPrice', type: 'price', props: { align: 'right', label: '结算金额(元)', minWidth: '120' }},
  { key: 'income', type: 'price', props: { align: 'right', label: '实际收入(元)', minWidth: '120' }},
  { key: 'supplierCost', type: 'price', props: { align: 'right', label: '供应商分成(元)', minWidth: '120' }},
  { key: 'cost', type: 'price', props: { align: 'right', label: '成本(元)', minWidth: '120' }},
  { key: 'sharingModel', type: 'filter', filter: sharingModelType, props: { label: '收入模式', minWidth: '100' }},
  { key: 'clientName', props: { label: '客户名称', minWidth: '110' }},
  { key: 'market', props: { label: '销售', minWidth: '110' }},
  { key: 'theme', props: { label: '合作类型', minWidth: '110' }},
  { key: 'authorizeTime', props: { label: '合作有效期', minWidth: '210' }},
  { key: 'area', props: { label: '合作品类', minWidth: '110' }},
  // { key: 'supplier', props: { label: '供应商', minWidth: '90' }},
  { key: 'ipAry', type: 'filter', filter: ipAryFilter, props: { label: 'IP形象', minWidth: '200' }},
  { key: 'contractCode', type: 'contractCode', props: { label: '关联合同', minWidth: '150' }},
  { key: 'costApprovalStatus', props: { label: '审批状态' }},
  { key: 'orderTime', type: 'time', props: { label: '下单日期', minWidth: '120' }},
  { key: 'writeOffStatus', type: 'filter', filter: setAccountState, props: { label: '核销状态', minWidth: '110' }},
  { key: 'createTime', type: 'time', props: { label: '创建时间 ', minWidth: '120' }}
];

// 成本来源：营销授权（3）
export const emojiInfoSetting = [
  { key: 'orderNum', type: 'emojiId', props: { label: '订单编号', minWidth: '184' }},
  { key: 'costPrice', type: 'price', props: { align: 'right', label: '结算金额(元)', minWidth: '100' }},
  { key: 'taxAmount', type: 'price', props: { align: 'right', label: '含税金额(元)', minWidth: '100' }},
  { key: 'cost', type: 'price', props: { align: 'right', label: '成本(元)', minWidth: '100' }},
  { key: 'licensePrice', type: 'price', props: { align: 'right', label: 'IP授权费(元)', minWidth: '120' }},
  { key: 'clientName', props: { label: '客户名称', minWidth: '110' }},
  { key: 'market', props: { label: '销售', minWidth: '110' }},
  { key: 'deliveryTime', type: 'time', props: { label: '交付时间', minWidth: '110' }},
  { key: 'remark', props: { label: '备注', minWidth: '130' }},
  { key: 'ipAry', type: 'filter', filter: ipAryFilter, props: { label: 'IP形象', minWidth: '200' }},
  { key: 'contractCode', type: 'contractCode', props: { label: '关联合同', minWidth: '150' }},
  { key: 'costApprovalStatus', props: { label: '审批状态' }},
  { key: 'orderTime', type: 'time', props: { label: '下单日期', minWidth: '120' }},
  { key: 'writeOffStatus', type: 'filter', filter: setAccountState, props: { label: '核销状态', minWidth: '110' }},
  { key: 'createTime', type: 'time', props: { label: '创建时间 ', minWidth: '120' }}
];

// 成本来源：项目订单（1）
const customerPropertyType = (status) => {
  const statusMap = {
    0: '非直客', 1: '直客'
  };
  return statusMap[status];
};
const projectStatusType = (status) => {
  if (status === undefined || status === null) return '--';
  const statusMap = {
    0: '待提交',
    1: '待初审',
    2: '待复审',
    3: '待确认',
    4: '待封存',
    5: '已封存'
  };
  return statusMap[status];
};
const departmentFilter = (data) => {
  if (data && data.length) {
    return data.map(i => i.name).filter(i => !!i).join('/');
  }
  return '--';
};
export const porjectInfoSetting = [
  { key: 'projectNum', type: 'projectNum', props: { label: '项目编号', minWidth: '184' }},
  { key: 'costName', props: { label: '成本项', minWidth: '150' }},
  { key: 'costPrice', type: 'price', props: { align: 'right', label: '结算金额(元)', minWidth: '100' }},
  { key: 'projectName', props: { label: '项目名称', minWidth: '120' }},
  { key: 'brandName', props: { label: '品牌名称', minWidth: '120' }},
  { key: 'clientName', props: { label: '客户名称', minWidth: '110' }},
  { key: 'customerProperty', type: 'filter', filter: customerPropertyType, props: { label: '客户性质', minWidth: '120' }},
  { key: 'taxAmount', type: 'price', props: { align: 'right', label: '含税金额(元)', minWidth: '100' }},
  { key: 'costAmount', type: 'price', props: { align: 'right', label: '成本金额(元)', minWidth: '100' }},
  { key: 'projectApprovalDate', type: 'time', props: { label: '立项日期', minWidth: '120' }},
  { key: 'finishDate', type: 'time', props: { label: '结案日期 ', minWidth: '120' }},
  { key: 'projectStatus', type: 'filter', filter: projectStatusType, props: { label: '状态', minWidth: '120' }},
  { key: 'projectRemark', props: { label: '项目备注', minWidth: '120' }},
  { key: 'receivePayDate', type: 'time', props: { label: '预计到款', minWidth: '120' }},
  { key: 'department', type: 'filter', filter: departmentFilter, props: { label: '所属部门', minWidth: '120' }},
  { key: 'creator', props: { label: '创建人', minWidth: '120' }},
  { key: 'contractCode', type: 'contractCode', props: { label: '关联合同', minWidth: '150' }},
  { key: 'costApprovalStatus', props: { label: '审批状态' }},
  { key: 'writeOffStatus', type: 'filter', filter: setAccountState, props: { label: '核销状态', minWidth: '110' }},
  { key: 'createDate', type: 'time', props: { label: '创建时间 ', minWidth: '120' }}
];
// 成本来源：项目渠道单（5）
export const porjectOrderInfoSetting = [
  { key: 'orderId', type: 'porjectOrder', props: { label: '订单编号', minWidth: '184' }},
  { key: 'costPrice', type: 'price', props: { align: 'right', label: '结算金额', minWidth: '100' }},
  { key: 'taxAmount', type: 'price', props: { align: 'right', label: '含税金额', minWidth: '100' }},
  { key: 'orderCost', type: 'price', props: { align: 'right', label: '总成本', minWidth: '100' }},
  { key: 'profit', props: { label: '毛利率', minWidth: '100' }},
  { key: 'costName', props: { label: '成本项', minWidth: '150' }},
  { key: 'priceBase', type: 'price', props: { align: 'right', label: '结算基数(元)', minWidth: '150' }},
  { key: 'market', props: { label: '销售', minWidth: '110' }},
  { key: 'projectName', props: { label: '项目名称', minWidth: '120' }},
  { key: 'customerName', props: { label: '客户名称', minWidth: '120' }},
  { key: 'projectTypeStr', props: { label: '项目类型', minWidth: '120' }},
  { key: 'resourceName', props: { label: '账号', minWidth: '130' }},
  { key: 'orderPlatform', props: { label: '下单平台', minWidth: '110' }},
  { key: 'costDescription', props: { label: '说明', minWidth: '120' }},
  // { key: 'organization', props: { label: '所属机构', minWidth: '120' }},
  { key: 'operateModeName', props: { label: '运营模式', minWidth: '120' }},
  { key: 'cooperation', props: { label: '合作运营方', minWidth: '120' }},
  { key: 'orderTime', type: 'time', props: { label: '下单时间', minWidth: '120' }},
  { key: 'brandName', props: { label: '品牌名称', minWidth: '120' }},
  { key: 'contractCode', type: 'contractCode', props: { label: '关联合同', minWidth: '150' }},
  { key: 'writeOffStatus', type: 'filter', filter: setAccountState, props: { label: '核销状态', minWidth: '110' }},
  { key: 'costApprovalStatus', props: { label: '审批状态' }}
];
export const setting = {
  '0': orderInfoSetting,
  '1': porjectInfoSetting,
  '2': ipInfoSetting,
  '3': emojiInfoSetting,
  '5': porjectOrderInfoSetting
};
